package org.gruposp2p.proyectokarma.controller

import org.gruposp2p.proyectokarma.domain.Document;
import com.sun.syndication.feed.synd.SyndCategoryImpl;

class FeedController {

    def index = { }
    
	def document = { 
		def appName = grailsApplication.metadata['app.name']
		render(feedType:"rss", feedVersion:"2.0") {
			title = message(code: 'proyectokarma.feed.title')
			link = "${grailsApplication.config.grails.serverURL}/feed/document"
			description = message(code: 'proyectokarma.feed.lastDocuments')
			Document.list(max:20, sort:"dateCreated", order:"desc").each() { document -> 
					entry(document.name) { 
						link = "${grailsApplication.config.grails.serverURL}${appName}/documents/${document.id}" 
						publishedDate = document.lastUpdated
						categories = document.documentTags.collect { documentTag ->
								return new SyndCategoryImpl(name: documentTag.tag.name, 
									taxonomyUri:"${grailsApplication.config.grails.serverURL}${appName}/tags/${documentTag.tag.id}")
							}
						author = document.peer.name
						document.content
					} 
			} 
		}
	}
	
}
